package com.xyb.controller;

import com.xyb.entity.Course;
import com.xyb.entity.CourseQuery;
import com.xyb.service.CourseService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("course")
public class CourseController {
    @Resource
    private CourseService courseService;

    @PostMapping("course")
    public String insertCourse(@RequestBody @Validated(Course.insert.class) Course course) {
        return courseService.insertCourse(course);
    }

    @PutMapping("course/{courseId}")
    public String updateCourseByCourseId(@PathVariable("courseId") Long courseId,@RequestBody @Validated(Course.update.class) Course course) {
        course.setCourseId(courseId);
        return courseService.updateCourseByCourseId(course);
    }
    @PutMapping("course/status/{courseId}")
    public String updateCourseStatusByCourseId(@PathVariable("courseId") Long courseId,@RequestBody @Validated(Course.status.class) Course course) {
        course.setCourseId(courseId);
        return courseService.updateCourseByCourseId(course);
    }

    @PostMapping("course/query")
    public List<Course> selectCourseList(@RequestBody CourseQuery courseQuery) {
        return courseService.selectCourseList(courseQuery);
    }

    @GetMapping("course/{courseId}")
    public Course selectCourseByCourseId(@PathVariable("courseId") Long courseId) {
        return courseService.selectCourseByCourseId(courseId);
    }

    @DeleteMapping("course/{courseId}")
    public String deleteCourseByCourseId(@PathVariable("courseId") Long courseId) {
        return courseService.deleteCourseByCourseId(courseId);
    }

    @PostMapping("course/order")
    public String updateCourseOrderByCourseId(@RequestBody Long[] courseIds) {
        return courseService.updateCourseOrderByCourseId(courseIds);
    }
}
